package cn.tedu.sp04.controller;

import cn.tedu.sp01.entity.Item;
import cn.tedu.sp01.entity.Order;
import cn.tedu.sp01.entity.User;
import cn.tedu.sp01.service.OrderService;
import cn.tedu.web.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * @author 金帮嘉诚 @date 2021-09-09 星期四 15:47
 */

@RestController
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    @GetMapping("/{orderId}")
    public JsonResult<Order> getOrder(@PathVariable String orderId) {
        Order order = orderService.getOrder(orderId);
        return JsonResult.ok().data(order);
    }

    @GetMapping("/add")
    public JsonResult<?> add() {//为了数据类型安全 写的泛型"?"
        Order order = new Order();
        order.setId("arseg32r8g");
        order.setUser(new User(8, "asd", "asd"));
        order.setItems(Arrays.asList(new Item(1, "商品1", 1),
                new Item(2, "商品2", 4),
                new Item(3, "商品3", 3),
                new Item(4, "商品4", 5),
                new Item(5, "商品5", 6),
                new Item(6, "商品6", 2),
                new Item(7, "商品7", 8)
        ));
        orderService.addOrder(order);
        return JsonResult.ok().msg("添加订单成功");

    }
    @GetMapping("/favicon.ico")
    public void ico() {
    }

}
